#include <stdio.h>
#include <malloc.h>
#include <stdbool.h>
void MergeSortNonR(int* a, int n, int* tmp)
{
	int gap = 1;
	while (gap < n)
	{
		for (int i = 0; i < n; i += 2 * gap)
		{
			int begin1 = i, end1 = i + gap - 1;
			int begin2 = i + gap, end2 = i + 2 * gap - 1;
			if (end1 >= n)
			{
				break;
			}
			if (begin2 >= n)
			{
				break;
			}
			if (end2 >= n)
			{
				end2 = n - 1;
			}
			int len = 0;
			while (begin1 <= end1 && begin2 <= end2)
			{
				if (a[begin1] <= a[begin2])
				{
					tmp[len++] = a[begin1++];
				}
				else
				{
					tmp[len++] = a[begin2++];
				}
			}
			while (begin1 <= end1)
			{
				tmp[len++] = a[begin1++];
			}
			while (begin2 <= end2)
			{
				tmp[len++] = a[begin2++];
			}
			memcpy(a + i, tmp, sizeof(int) * (end2 - i + 1));
		}
		gap *= 2;
	}

}

int* sortArray(int* nums, int numsSize, int* returnSize) {
	int* tmp = (int*)malloc(numsSize * sizeof(int));
	MergeSortNonR(nums, numsSize, tmp);
	*returnSize = numsSize;
	return nums;
}
int main()
{
   
    return 0;
}
